package com.gome.extract;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpURLConnection;
import java.net.URL;

public class TestURL 
{
	String urlString;

	public TestURL(String urlString) 
	{
		this.urlString = urlString;
	}
	
	public String getURL() throws Exception 
	{
		CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
		//生成一个URL对象 
		URL url = new URL(urlString);
		//打开URL 
		HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
		//得到输入流，即获得了网页的内容 
		BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "utf-8"));
		String line;
		// 读取输入流的数据，并显示
		String result = "";
		while ((line = reader.readLine()) != null)
		{
			result += line;
//			System.out.println(line);
		}
		return result;
	}
 
	public static void main(String[] args) throws Exception 
	{
		TestURL client = new TestURL("http://t.dianping.com/deal/11864836");
		client.getURL();
	}
}